package com.demo.web.dao;

import com.demo.web.domain.LearnResouce;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Map;

/**
 * @Author: KUN
 * @Date: 2018/3/7 15:24
 */

@Mapper
public interface LearnResouceMapper {
    int add(LearnResouce learnResouce);
    int update(LearnResouce learnResouce);
    int deleteByIds(String[] ids);
    LearnResouce queryLearnResouceById(Long id);
    public List<LearnResouce> queryLearnResouceList(Map<String, Object> params);
}
//@Component
//@Mapper
//public interface LearnResouceMapper {
//    @Insert("insert into learn_resource(author, title,url) values(#{author},#{title},#{url})")
//    int add(LearnResouce learnResouce);
//
//    @Update("update learn_resource set author=#{author},title=#{title},url=#{url} where id = #{id}")
//    int update(LearnResouce learnResouce);
//
//    @DeleteProvider(type = LearnSqlBuilder.class, method = "deleteByids")
//    int deleteByIds(@Param("ids") String[] ids);
//
//
//    @Select("select * from learn_resource where id = #{id}")
//    @Results(id = "learnMap", value = {
//            @Result(column = "id", property = "id", javaType = Long.class),
//            @Result(property = "author", column = "author", javaType = String.class),
//            @Result(property = "title", column = "title", javaType = String.class)
//    })
//    LearnResouce queryLearnResouceById(@Param("id") Long id);
//
//    @SelectProvider(type = LearnSqlBuilder.class, method = "queryLearnResouceByParams")
//    List<LearnResouce> queryLearnResouceList(Map<String, Object> params);
//
//    class LearnSqlBuilder {
//        public String queryLearnResouceByParams(final Map<String, Object> params) {
//            StringBuffer sql =new StringBuffer();
//            sql.append("select * from learn_resource where 1=1");
//            if(!StringUtil.isNull((String)params.get("author"))){
//                sql.append(" and author like '%").append((String)params.get("author")).append("%'");
//            }
//            if(!StringUtil.isNull((String)params.get("title"))){
//                sql.append(" and title like '%").append((String)params.get("title")).append("%'");
//            }
//            System.out.println("查询sql=="+sql.toString());
//            return sql.toString();
//        }
//
//        //删除的方法
//        public String deleteByids(@Param("ids") final String[] ids){
//            StringBuffer sql =new StringBuffer();
//            sql.append("DELETE FROM learn_resource WHERE id in(");
//            for (int i=0;i<ids.length;i++){
//                if(i==ids.length-1){
//                    sql.append(ids[i]);
//                }else{
//                    sql.append(ids[i]).append(",");
//                }
//            }
//            sql.append(")");
//            return sql.toString();
//        }
//    }
//
//
//}
